#pragma once
#include "ws2812b.h"
#include <thread>
#include <atomic>
#include <list>
#include <mutex>
#include "wiringPi.h"
#include <iostream>
#include "easylogging++.h"
#ifdef MyCompileEnvir //add_definitions(-DMyCompileEnvir)
    #include <jsoncpp/json/json.h> //需要安装 libjsoncpp-dev
#else 
    #include "rtc_base/strings/json.h" //编译环境中带有的
#endif
#define LED_num 5 
struct LED_RGB{
    unsigned char R = 0;
    unsigned char G = 0;
    unsigned char B = 0;
    LED_RGB(unsigned char _R, unsigned char _G, unsigned char _B):R(_R),G(_G),B(_B){} //有参构造
    LED_RGB():R(0),G(0),B(0){}
};

struct LifeLampStruct{
    LED_RGB lamps[LED_num];
    unsigned char n = 1;
    int time = 100;
};

class LifeLampsControl
{
public:
    LifeLampsControl(void);
    ~LifeLampsControl();
    void init(unsigned char pin_LED = 12, unsigned char pwmFunALT = 0, unsigned int numLED = LED_num, ws2812b::RPI_Version piVer = ws2812b::PI_Zero_2W);
    void write2ws2812b(LifeLampStruct & lamps);
    void decodeJsonList(Json::Value lifeLampsList, bool IsLoopEnable);
    void testDemo(void);
private:
    ws2812b *lifeLamps;
    bool LoopEnable_cur; //当前是否循环
    std::list<LifeLampStruct> lifeLampsControlList;
    bool insertData(int n,LifeLampStruct & lls);
    LED_RGB decodeIntToRGB(int dat);
    void controlLampsThread(void);
    bool KillThread;
    std::atomic<bool> ReInit;//
    std::mutex ws2812bMutex;
};